package com.fanshuai2.niuke.strings;

import java.util.Scanner;
import java.util.regex.Pattern;

public class StringMatch2 {
    static boolean match(String pattern, String text) {
        pattern = pattern.toLowerCase();
        text = text.toLowerCase();

        String regex = pattern.replaceAll("\\*{2,}", "\\*");
        regex = regex.replaceAll("\\*", "[a-z0-9]{0,}");
        regex = regex.replaceAll("\\?", "[a-z0-9]{1}");

        return Pattern.compile(regex).matcher(text).matches();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextLine()) {
            String pattern = in.nextLine();
            String text = in.nextLine();
            System.out.println(match(pattern, text));
        }
    }
}
